package com.yztc.youbadbad.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.youbadbad.R;
import com.yztc.youbadbad.bean.oversea.OverseaImgBean;
import com.yztc.youbadbad.bean.oversea.OverseaImgLikeBean;
import com.yztc.youbadbad.helper.RecyclerViewAdapterHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 首页 推荐的适配器 不同item布局
 */

public class OverseaRecyclerAdapter extends RecyclerViewAdapterHelper<Object> {
    public static final int STATE1 = 0, STATE2 = 1;

    public OverseaRecyclerAdapter(Context context, List<Object> list) {

        super(context, list);
    }


    @Override
    public int getItemViewType(int position) {
        Log.e("tag", "->" + position);
        if (mList.get(position) instanceof OverseaImgBean) {
            return STATE1;
        }else if(mList.get(position) instanceof OverseaImgLikeBean){
            return STATE2;
        }
        return STATE2;
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        switch (viewType) {
            case STATE1:
                view = mInflater.inflate(R.layout.item_other_ad, parent, false);
                return new ViewHolder1(view);
            case STATE2:
                view = mInflater.inflate(R.layout.item_oversea_like, parent, false);
                return new ViewHolder2(view);
        }
        return null;
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        Log.e("tag", "2->" + position);
        if (holder instanceof ViewHolder1) {
            ViewHolder1 holder1 = (ViewHolder1) holder;
            OverseaImgBean overseaImgBean = (OverseaImgBean) mList.get(position);
            Log.e("tag", "->" + overseaImgBean.getAdPic());
            holder1.titleFirTv.setText(overseaImgBean.getAdWord());
            holder1.titleSecTv.setText(overseaImgBean.getAdName());
            Glide.with(mContext).load(overseaImgBean.getAdPic()).into(holder1.eventImgIv);
        } else if (holder instanceof ViewHolder2) {
            ViewHolder2 holder2= (ViewHolder2) holder;
            OverseaImgLikeBean overseaImgLikeBean= (OverseaImgLikeBean) mList.get(position);
            holder2.tvContentFirst.setText(overseaImgLikeBean.getBrandName());
            holder2.tvContentSecond.setText(overseaImgLikeBean.getName());
            holder2.tvContentThird.setText("￥ "+overseaImgLikeBean.getStorePrice());
            Glide.with(mContext).load(overseaImgLikeBean.getImageUrl()).into(holder2.showImage);

        }
    }

    static class ViewHolder1 extends RecyclerView.ViewHolder {
        @BindView(R.id.event_img_iv)
        ImageView eventImgIv;
        @BindView(R.id.title_fir_tv)
        TextView titleFirTv;
        @BindView(R.id.title_sec_tv)
        TextView titleSecTv;


        public ViewHolder1(View itemView) {

            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    static class ViewHolder2 extends RecyclerView.ViewHolder {
        @BindView(R.id.show_image)
        ImageView showImage;
        @BindView(R.id.tvContent_first)
        TextView tvContentFirst;
        @BindView(R.id.tvContent_second)
        TextView tvContentSecond;
        @BindView(R.id.tvContent_third)
        TextView tvContentThird;

        public ViewHolder2(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
